class Solution {
public:
    class cmp{
    public:
        bool operator()(vector<int>& a,vector<int>& b){
            return a[0] < b[0];
        }
    };
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        vector<vector<int> > res;
        int index = 0;
        if(intervals.size() == 0) return res;
     //   sort(intervals.begin(),intervals.end(),cmp());
        
        sort(intervals.begin(),intervals.end(),[&](vector<int>& a,vector<int>& b)->bool
             {return a[0] < b[0];});
        
        for(int i = 1;i < intervals.size();i++){
            if(intervals[i][0] <= intervals[i - 1][1]){
                intervals[i][0] = intervals[i-1][0];
                intervals[i][1] = max(intervals[i - 1][1],intervals[i][1]);
            }else{
                res.push_back(intervals[i-1]);
            }
        }
            res.push_back(intervals[intervals.size() - 1]);
        return res;
    }
};
